import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
from pathlib import Path
import subprocess
from tools.psf_inspector import SExtractorRunner, PSFExRunner, PSFExInspector
# Example usage
if __name__ == '__main__':
    img = './images/12377/mb_sc_12377_u_20221124164437_276_sciimg.fits'

    # 1. Run SExtractor
    sex_runner = SExtractorRunner(
        sex_path='sex', config_path='./config', output_path='result',sexconfig='/mnt/7b21f1e1-eb25-4cd5-bdb5-06d7d82fa253/Temp/force_photmetry/config/default_ori.sex', sexparamconfig='./config/default_psfex.param'
    )
    catalog, check_imgs = sex_runner.run(
        img, detect_thresh=5.0, analysis_thresh=3.0, detect_minarea=10
    )
    print('Catalog generated:', catalog)

    # 2. Run PSFEx
    psf_runner = PSFExRunner(
        psfex_path='psfex', config_file='./config/default.psfex'
    )
    psf_file, checkplots = psf_runner.run(catalog)
    print('PSF model file:', psf_file)



    
